package edu.hcmus.sow.domain;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonIgnore;

/**
 */

@Entity
@NamedQueries({
      @NamedQuery(name = "findAllFileRevisions", query = "select myFileRevision from FileRevision myFileRevision"),
      @NamedQuery(name = "findFileRevisionByApprovalStatus", query = "select myFileRevision from FileRevision myFileRevision where myFileRevision.approvalStatus = ?1"),
      @NamedQuery(name = "findFileRevisionByApprovalStatusContaining", query = "select myFileRevision from FileRevision myFileRevision where myFileRevision.approvalStatus like ?1"),
      @NamedQuery(name = "findFileRevisionByApprovedDate", query = "select myFileRevision from FileRevision myFileRevision where myFileRevision.approvedDate = ?1"),
      @NamedQuery(name = "findFileRevisionByCreatedDate", query = "select myFileRevision from FileRevision myFileRevision where myFileRevision.createdDate = ?1"),
      @NamedQuery(name = "findFileRevisionById", query = "select myFileRevision from FileRevision myFileRevision where myFileRevision.id = ?1"),
      @NamedQuery(name = "findFileRevisionByPrimaryKey", query = "select myFileRevision from FileRevision myFileRevision where myFileRevision.id = ?1"),
      @NamedQuery(name = "findFileRevisionByReason", query = "select myFileRevision from FileRevision myFileRevision where myFileRevision.reason = ?1"),
      @NamedQuery(name = "findFileRevisionByRevision", query = "select myFileRevision from FileRevision myFileRevision where myFileRevision.revision = ?1"),
      @NamedQuery(name = "findFileRevisionByRowkey", query = "select myFileRevision from FileRevision myFileRevision where myFileRevision.rowkey = ?1"),
      @NamedQuery(name = "findFileRevisionBySize", query = "select myFileRevision from FileRevision myFileRevision where myFileRevision.size = ?1") })
@Table(catalog = "sow", name = "file_revision")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain", name = "FileRevision")
public class FileRevision implements Serializable {
   private static final long serialVersionUID = 1L;

   /**
	 */

   @Column(name = "ID", nullable = false)
   @Basic(fetch = FetchType.EAGER)
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @XmlElement
   Integer id;
   /**
	 */

   @Column(name = "NAME", length = 100)
   @Basic(fetch = FetchType.EAGER)
   @XmlElement
   String name;
   /**
    */

   @Column(name = "SIZE", precision = 12, nullable = false)
   @Basic(fetch = FetchType.EAGER)
   @XmlElement
   Long size;
   /**
    */

   @Column(name = "TYPE", length = 100)
   @Basic(fetch = FetchType.EAGER)
   @XmlElement
   String type;
   /**
	 */

   @Column(name = "ROWKEY", length = 40, nullable = false)
   @Basic(fetch = FetchType.EAGER)
   @XmlElement
   String rowkey;
   /**
	 */

   @Column(name = "REVISION", nullable = false)
   @Basic(fetch = FetchType.EAGER)
   @XmlElement
   Integer revision;
   /**
	 */
   @Temporal(TemporalType.TIMESTAMP)
   @Column(name = "CREATED_DATE")
   @Basic(fetch = FetchType.EAGER)
   @XmlElement
   Calendar createdDate;
   /**
	 */
   @Temporal(TemporalType.TIMESTAMP)
   @Column(name = "APPROVED_DATE")
   @Basic(fetch = FetchType.EAGER)
   @XmlElement
   Calendar approvedDate;
   /**
	 */

   @Column(name = "REASON", columnDefinition = "TEXT")
   @Basic(fetch = FetchType.EAGER)
   @Lob
   @XmlElement
   String reason;
   /**
	 */

   @Temporal(TemporalType.TIMESTAMP)
   @Column(name = "APPROVAL_DUE_DATE")
   @Basic(fetch = FetchType.EAGER)
   @XmlElement
   Calendar approvalDueDate;
   /**
    */

   @Column(name = "APPROVAL_REMINDER", length = 10)
   @Basic(fetch = FetchType.EAGER)
   @XmlElement
   String approvalReminder;
   /**
    */

   @Column(name = "APPROVAL_STATUS", length = 3)
   @Basic(fetch = FetchType.EAGER)
   @XmlElement
   String approvalStatus;

   /**
	 */
   @ManyToOne(fetch = FetchType.EAGER)
   @JoinColumns({ @JoinColumn(name = "CREATED_BY", referencedColumnName = "ID") })
   @XmlTransient
   User userByCreatedBy;
   /**
	 */
   @ManyToOne(fetch = FetchType.EAGER)
   @JoinColumns({ @JoinColumn(name = "APPROVED_BY", referencedColumnName = "ID") })
   @XmlTransient
   User userByApprovedBy;
   /**
	 */
   @ManyToOne(fetch = FetchType.EAGER)
   @JoinColumns({ @JoinColumn(name = "FILE_ID", referencedColumnName = "ID", nullable = false) })
   @XmlTransient
   File file;

   /**
    */
   @OneToMany(mappedBy = "fileRevision", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
   @XmlElement(name = "", namespace = "")
   java.util.Set<edu.hcmus.sow.domain.FileRevisionComment> fileRevisionComments;

   @Column(name = "FILE_ID", updatable = false, insertable = false)
   private Integer fileID;

   public Integer getFileID() {
      return fileID;
   }

   public void setFileID(Integer fileID) {
      this.fileID = fileID;
   }

   /**
	 */
   public void setId(Integer id) {
      this.id = id;
   }

   /**
	 */
   public Integer getId() {
      return this.id;
   }

   /**
    */
   public void setName(String name) {
      this.name = name;
   }

   /**
    */
   public String getName() {
      return this.name;
   }

   /**
	 */
   public void setSize(Long size) {
      this.size = size;
   }

   /**
	 */
   public Long getSize() {
      return this.size;
   }

   /**
    */

   public String getType() {
      return type;
   }

   /**
    */

   public void setType(String type) {
      this.type = type;
   }

   /**
	 */
   public void setRowkey(String rowkey) {
      this.rowkey = rowkey;
   }

   /**
	 */
   public String getRowkey() {
      return this.rowkey;
   }

   /**
	 */
   public void setRevision(Integer revision) {
      this.revision = revision;
   }

   /**
	 */
   public Integer getRevision() {
      return this.revision;
   }

   /**
	 */
   public void setCreatedDate(Calendar createdDate) {
      this.createdDate = createdDate;
   }

   /**
	 */
   public Calendar getCreatedDate() {
      return this.createdDate;
   }

   /**
	 */
   public void setApprovedDate(Calendar approvedDate) {
      this.approvedDate = approvedDate;
   }

   /**
	 */
   public Calendar getApprovedDate() {
      return this.approvedDate;
   }

   /**
	 */
   public void setReason(String reason) {
      this.reason = reason;
   }

   /**
	 */
   public String getReason() {
      return this.reason;
   }

   /**
    */
   public void setApprovalDueDate(Calendar approvalDueDate) {
      this.approvalDueDate = approvalDueDate;
   }

   /**
    */
   public Calendar getApprovalDueDate() {
      return this.approvalDueDate;
   }

   /**
    */
   public void setApprovalReminder(String approvalReminder) {
      this.approvalReminder = approvalReminder;
   }

   /**
    */
   public String getApprovalReminder() {
      return this.approvalReminder;
   }

   /**
	 */
   public void setApprovalStatus(String approvalStatus) {
      this.approvalStatus = approvalStatus;
   }

   /**
	 */
   public String getApprovalStatus() {
      return this.approvalStatus;
   }

   /**
	 */
   public void setUserByCreatedBy(User userByCreatedBy) {
      this.userByCreatedBy = userByCreatedBy;
   }

   /**
	 */
   @JsonIgnore
   public User getUserByCreatedBy() {
      return userByCreatedBy;
   }

   /**
	 */
   public void setUserByApprovedBy(User userByApprovedBy) {
      this.userByApprovedBy = userByApprovedBy;
   }

   /**
	 */
   @JsonIgnore
   public User getUserByApprovedBy() {
      return userByApprovedBy;
   }

   /**
	 */
   public void setFile(File file) {
      this.file = file;
   }

   /**
	 */
   @JsonIgnore
   public File getFile() {
      return file;
   }

   /**
    */
   public void setFileRevisionComments(Set<FileRevisionComment> fileRevisionComments) {
      this.fileRevisionComments = fileRevisionComments;
   }

   /**
    */
   @JsonIgnore
   public Set<FileRevisionComment> getFileRevisionComments() {
      if (fileRevisionComments == null) {
         fileRevisionComments = new java.util.LinkedHashSet<edu.hcmus.sow.domain.FileRevisionComment>();
      }
      return fileRevisionComments;
   }

   /**
	 */
   public FileRevision() {
   }

   /**
    * Copies the contents of the specified bean into this bean.
    * 
    */
   public void copy(FileRevision that) {
      setId(that.getId());
      setName(that.getName());
      setSize(that.getSize());
      setType(that.getType());
      setRowkey(that.getRowkey());
      setRevision(that.getRevision());
      setCreatedDate(that.getCreatedDate());
      setApprovedDate(that.getApprovedDate());
      setReason(that.getReason());
      setApprovalDueDate(that.getApprovalDueDate());
      setApprovalReminder(that.getApprovalReminder());
      setApprovalStatus(that.getApprovalStatus());
      setUserByCreatedBy(that.getUserByCreatedBy());
      setUserByApprovedBy(that.getUserByApprovedBy());
      setFile(that.getFile());
//      setFileRevisionComments(new java.util.LinkedHashSet<edu.hcmus.sow.domain.FileRevisionComment>(
//            that.getFileRevisionComments()));
   }

   /**
    * Returns a textual representation of a bean.
    * 
    */
   public String toString() {

      StringBuilder buffer = new StringBuilder();

      buffer.append("id=[").append(id).append("] ");
      buffer.append("name=[").append(name).append("] ");
      buffer.append("size=[").append(size).append("] ");
      buffer.append("type=[").append(type).append("] ");
      buffer.append("rowkey=[").append(rowkey).append("] ");
      buffer.append("revision=[").append(revision).append("] ");
      buffer.append("createdDate=[").append(createdDate).append("] ");
      buffer.append("approvedDate=[").append(approvedDate).append("] ");
      buffer.append("reason=[").append(reason).append("] ");
      buffer.append("approvalDueDate=[").append(approvalDueDate).append("] ");
      buffer.append("approvalReminder=[").append(approvalReminder).append("] ");
      buffer.append("approvalStatus=[").append(approvalStatus).append("] ");

      return buffer.toString();
   }

   /**
	 */
   @Override
   public int hashCode() {
      final int prime = 31;
      int result = 1;
      result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
      return result;
   }

   /**
	 */
   public boolean equals(Object obj) {
      if (obj == this)
         return true;
      if (!(obj instanceof FileRevision))
         return false;
      FileRevision equalCheck = (FileRevision) obj;
      if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
         return false;
      if (id != null && !id.equals(equalCheck.id))
         return false;
      return true;
   }
}
